<?php include("header.inc.php") ?>
<?php include("navigation.inc.php")?>       
<?php include("left.inc.php")?>       
<div id="mainContent" class="grid_7" style="margin: 10px 0px 10px 0px">
 			<div class="thanhtieude">
                <div class="stt"><h2>STT</h2></div>
                <div class="ten"><h2>Thời Khóa Biểu</h2></div>
                <div class="download" style="background:url(img/thanhcongvan.PNG) repeat-x;"><h2>Download</h2></div>
            </div>
            
            <?php      
	$display = 10;
        if (isset($_GET['page']) && (int)$_GET['page']) {
 	           $page = $_GET['page'];	
        } else {                   
    	       $sql = "SELECT COUNT(idcongvan) FROM congvan WHERE status = 1";
               $query = mysql_query($sql) or die("Error query count ".mysql_error($conn));
               $rows = mysql_fetch_array($query);
               $record = $rows[0];
	           if ($record > $display) {
    	             $page = ceil($record/$display);	
               } else {
                     $page = 1;	
               }                
        $start = (isset($_GET['start']) && (int)$_GET['start'])?$_GET['start']:0;			   		
		$sql = "SELECT  * FROM thoikhoabieu WHERE STATUS = 1 ORDER BY thoigian DESC LIMIT $start,$display";
		$query = mysql_query($sql) or die("Can't query thoikhoabieu");
		$stt = 0;
		while ($row = mysql_fetch_array($query))
		{
			$stt++;
			?>
            <div class="thanhtieude">
                <div class="stt">
                    <?php echo $stt?>
                </div>
                <div class="ten" style="text-align:left;">
                    <?php echo $row['tieude'];?>
                </div>
                <div class="download">
                    <a href="upload/files/tkb/<?php echo $row['luutru']?>"><img src="img/Download.png" /></a>
                </div>
            </div>
		<?php 
		}
		}
		?>
        
        <div class="pagelist">
        	 <ul>
        <?php						
					if($page > 1) {
						$next = $start + $display;
						$previous = $start - $display;
						$current = ($start/$display) + 1;				
						if ($current != 1) {
							echo "<li><a href='thoikhoabieu.php?start=$previous'>Quay Lại</a></li>";	
						} 
						for ($i=1;$i<=$page;$i++){
							if($i != $current) {
								echo "<li><a href='thoikhoabieu.php?start=".($display*($i-1))."'>$i</a></li>";	
							} else {
								echo "<li class='current'>$i</li>";		
							}
						}
						if ($current != $page){
							echo "<li><a href='thoikhoabieu.php?start=$next'>Tiếp</a></li>";	
						}
					}
		?>
	         </ul>
    	</div>                                          
</div>
     
<?php include("right.inc.php")?>  
<?php include("footer.inc.php")?>  

